package com.kuang.controller.nginxtest;

import com.kuang.utils.ip.IpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2021/8/23 12:31
 */
@RestController
public class TestController {


    @Value("${server.port}")
    private String port;


    @GetMapping("/nginx/test")
    public Map<String, String> test(HttpServletRequest request) {
        Map<String, String> map = new HashMap<>();
        String ipAddr = IpUtils.getIpAddr(request);
        map.put("port1", request.getLocalPort() + "");
        map.put("port2", request.getServerPort() + "");
        map.put("port3", request.getRemotePort() + "");
        map.put("url", request.getRequestURL().toString());
        map.put("port4", port);
        map.put("ipAddr", ipAddr);
        return map;
    }


    @GetMapping("/c/list")
    public Map<String, String> courselist(HttpServletRequest request) {
        Map<String, String> map = new HashMap<>();
        String ipAddr = IpUtils.getIpAddr(request);
        map.put("port1", request.getLocalPort() + "");
        map.put("port2", request.getServerPort() + "");
        map.put("port3", request.getRemotePort() + "");
        map.put("url", request.getRequestURL().toString());
        map.put("port4", port);
        map.put("ipAddr", ipAddr);
        return map;
    }

    @GetMapping("/u/info")
    public Map<String, String> userlist(HttpServletRequest request) {
        Map<String, String> map = new HashMap<>();
        String ipAddr = IpUtils.getIpAddr(request);
        map.put("port1", request.getLocalPort() + "");
        map.put("port2", request.getServerPort() + "");
        map.put("port3", request.getRemotePort() + "");
        map.put("url", request.getRequestURL().toString());
        map.put("port4", port);
        map.put("ipAddr", ipAddr);
        return map;
    }

}
